package com.shenmazong.lambda;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

/**
 * @program: server-java-demo
 * @description: 验证是否是延迟加载
 * @author: 亮子说编程
 * @create: 2020-10-19 16:33
 **/

@Data
@NoArgsConstructor
@AllArgsConstructor
class Student {
    private String name;
    private Integer age;
}

public class StreamApiTest {

    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();

        //
        list.add(new Student("武大郎", 50));
        list.add(new Student("潘金莲", 19));
        list.add(new Student("武松", 29));
        list.add(new Student("西门庆", 35));

        //
        Stream<Student> stream = list.stream().filter((i) -> {
            System.out.println("验证是否是延迟加载");
            return  i.getAge() > 30;
        });

        //
        System.out.println("=== end ===");

        stream.forEach(System.out::println);
        //System.out.println("=== finish ===");
    }
}
